﻿@model Product
@{ 
    StoreInitials storeInitials = (StoreInitials)ViewData["StoreInitials"];
    int storeInitialRow = 3;
}
@section ToolBar{
    <div class="r-c-list">
        <span>设置期初库存-@Model.ProductName (@Model.ProductNo)</span>
    </div>
    <div class="r-c-tool">
        <a href="javascript:location.reload();" class="l-btn fa fa-refresh"></a>
        <a href="javascript:void(0);" class="l-btn fa fa-search"></a>
    </div>
}
<form mark="LedinghuoForm" action="@Url.Action("Index")" method="POST">
    <div class="l-m-table form form-item l-margin-t10" style="width:800px;">
        <tablefor for="StoreInitial">
            <NewTr allow="true" template="template" callback="callback"></NewTr>
            <DeleteTr allow="true"></DeleteTr>
        </tablefor>
        <table id="StoreInitial" mark="LedinghuoTable">
            <tr class="bgc3">
                <th width="300">仓库</th>
                <th width="200">批号</th>
                <th width="100">数量</th>
                <th width="200">操作</th>
            </tr>
            @if (storeInitials == null || storeInitials.Items.Count <= 0)
            {
                for (var i = 0; i < storeInitialRow; i++)
                {
                    <tr index="@i">
                        <td>
                            <input name="StoreBox_@i" id="StoreBox_@i" type="text" class="inp-text full bc1 bgc0 inp-lg7 inp-hg6 commonbox" fa="fa-angle-down" />
                            <input type="hidden" name="StoreId_@i" id="StoreId_@i" />
                            <acronym for="StoreId_@i"><req message="仓库不能为空"></req></acronym>
                            <acronym for="StoreBox_@i"><req message="仓库不能为空"></req></acronym>
                        </td>
                        <td><input type="text" class="inp-text full" name="LotNo_@i" /><acronym for="LotNo_@i"><req message="批号不能为空"></req></acronym></td>
                        <td><input type="text" class="inp-text full" name="Quantity_@i" /><acronym for="Quantity_@i"><req message="数量不能为空"></req></acronym></td>
                        <td><a href="javascript:void(0)" mark="del">删除</a></td>
                    </tr>
                }
            }
            else
            {
                storeInitialRow = storeInitials.Items.Count;
                int i = 0;
                foreach (StoreInitial p in storeInitials.Items)
                {
                    <tr index="@i">
                        <td>
                            <input name="StoreBox_@i" id="StoreBox_@i" value="@p.Store.StoreName" type="text" class="inp-text full bc1 bgc0 inp-lg7 inp-hg6 commonbox" fa="fa-angle-down" />
                            <input type="hidden" name="StoreId_@i" id="StoreId_@i" value="@p.StoreId" />
                            <acronym for="StoreId_@i"><req message="仓库不能为空"></req></acronym>
                            <acronym for="StoreBox_@i"><req message="仓库不能为空"></req></acronym>
                        </td>
                        <td><input type="text" class="inp-text full" name="LotNo_@i" value="@p.LotNo" /><acronym for="LotNo_@i"><req message="批号不能为空"></req></acronym></td>
                        <td><input type="text" class="inp-text full" name="Quantity_@i" value="@p.Quantity.QuantityFormat()" /><acronym for="Quantity_@i"><req message="数量不能为空"></req></acronym></td>
                        <td><a href="javascript:void(0)" mark="del">删除</a></td>
                    </tr>
                    i++;
                }
            }
        </table>
    </div>
    <div class="l-padding-a20-10 t-c">@Html.LButton("保存")</div>
    @Html.HiddenFor(p => Model.ProductId)
    @Html.HiddenFor(p => Model.ProductName)
    <input type="hidden" name="StoreInitialLineRow" id="StoreInitialLineRow" value="@storeInitialRow" />
</form>
@Html.LPageError()

<script type="text/javascript">
    $(function () {
        var bindEvent = function (self) {
            $(self).find("input[name^=StoreBox_]").store(function ($this,$s) {
                var index = $s.attr("name").split("_")[1];
                $(self).find("input[name=StoreId_" + index + "]").val($this.attr("data"));
            });
        };
        $("#StoreInitial").find("tr").each(function () {
            var self = this;
            bindEvent(self);
        });
        window.callback = function (index) {
            var html = [];
            html.push('<tr index="' + index + '">');
            html.push('    <td>');
            html.push('        <input name="StoreBox_' + index + '" id="StoreBox_' + index + '" type="text" class="inp-text full bc1 bgc0 inp-lg7 inp-hg6 commonbox"  fa="fa-angle-down" />');
            html.push('        <input type="hidden"  name="StoreId_' + index + '" id="StoreId_' + index + '" />');
            html.push('        <acronym for="StoreId_' + index + '"><req message="仓库不能为空"></req></acronym>');
            html.push('        <acronym for="StoreBox_' + index + '"><req message="仓库不能为空"></req></acronym>');
            html.push('    </td>');
            html.push('    <td><input type="text" class="inp-text full" name="LotNo_' + index + '" /><acronym for="LotNo_' + index + '"><req message="批号不能为空"></req></acronym></td>');
            html.push('    <td><input type="text" class="inp-text full" name="Quantity_' + index + '" /><acronym for="Quantity_' + index + '"><req message="数量不能为空"></req></acronym></td>');
            html.push('    <td><a href="javascript:void(0)" mark="del">删除</a></td>');
            html.push('</tr>');
            return html.join("");
        };
        window.template = function (self) {
            var linerow = $("#StoreInitialLineRow").val();
            $("#StoreInitialLineRow").val(linerow + 1);
            bindEvent(self);
        }
    });
</script>


@*<div style="height:300px;margin-top:20px;">
    <input type="text" class="inp-text bc1 bgc0 inp-lg7 inp-hg6" autocomplete="off" data="1" fa="fa-angle-down" valuefor="fileter select" />
</div>
/*
属性意义：
autocomplete="off" 关闭文本框输入是的提示（这个很讨厌）
data="1" input 的真实值，有时候显示值与真实值不一样
fa="fa fa-angle-down" fa 是标识是否有文本框后边的按钮，对应的值是按钮的样式
valuefor="fileter select" 当在文本框中输入值的时候：过滤 并 筛选
*/*@